home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / X11 / wais / waisgate / HTFormat.h < prev    next >
C/C++ Source or Header  |  1995-05-09  |  8KB  |  283 lines

  1. /*                                            HTFormat: The format manager in the WWW Library
  2.                             MANAGE DIFFERENT DOCUMENT FORMATS
  3.                                              
  4.    Here we describe the functions of the HTFormat module which handles conversion between
  5.    different data representations.  (In MIME parlance, a representation is known as a
  6.    content-type. In WWW  the term "format" is often used as it is shorter).
  7.    
  8.    This module is implemented by HTFormat.c. This hypertext document is used to generate
  9.    the HTFormat.h inlude file.
  10.    
  11. Preamble
  12.  
  13.  */
  14. #ifndef HTFORMAT_H
  15. #define HTFORMAT_H
  16.  
  17. #include "HTUtils.h"
  18. #include "HTStream.h"
  19. #include "HTAtom.h"
  20. #include "HTList.h"
  21.  
  22. #ifdef SHORT_NAMES
  23. #define HTOutputSource HTOuSour
  24. #define HTOutputBinary HTOuBina
  25. #endif
  26.  
  27. /*
  28.  
  29. The HTFormat type
  30.  
  31.    We use the HTAtom object for holding representations. This allows faster manipulation
  32.    (comparison and copying) that if we stayed with strings.
  33.    
  34.  */
  35. typedef HTAtom * HTFormat;
  36.                         
  37. /*
  38.  
  39.    These macros (which used to be constants) define some basic internally referenced
  40.    representations.  The www/xxx ones are of course not MIME standard.
  41.    
  42.    www/source  is an output format which leaves the input untouched. It is useful for
  43.    diagnostics, and for users who want to see the original, whatever it is.
  44.    
  45.  */
  46.                         /* Internal ones */
  47. #define WWW_SOURCE HTAtom_for("www/source")     /* Whatever it was originally*/
  48.  
  49. /*
  50.  
  51.    www/present represents the user's perception of the document.  If you convert to
  52.    www/present, you present the material to the user.
  53.    
  54.  */
  55. #define WWW_PRESENT HTAtom_for("www/present")   /* The user's perception */
  56.  
  57. /*
  58.  
  59.    The message/rfc822 format means a MIME message or a plain text message with no MIME
  60.    header. This is what is returned by an HTTP server.
  61.    
  62.  */
  63. #define WWW_MIME HTAtom_for("www/mime")         /* A MIME message */
  64. /*
  65.  
  66.    www/print is like www/present except it represents a printed copy.
  67.    
  68.  */
  69. #define WWW_PRINT HTAtom_for("www/print")       /* A printed copy */
  70.  
  71. #define WWW_PLAINTEXT   HTAtom_for("text/plain")
  72. #define WWW_POSTSCRIPT  HTAtom_for("application/postscript")
  73. #define WWW_RICHTEXT    HTAtom_for("application/rtf")
  74. #define WWW_HTML        HTAtom_for("text/html")
  75. #define WWW_BINARY      HTAtom_for("application/binary")
  76. /*
  77.  
  78.    We must include the following file after defining HTFormat, to which it makes
  79.    reference.
  80.    
  81.  */
  82. #include "HTAnchor.h"
  83.  
  84. /*
  85.  
  86. The HTPresentation and HTConverter types
  87.  
  88.    This HTPresentation structure represents a possible conversion algorithm from one
  89.    format to annother.  It includes a pointer to a conversion routine. The conversion
  90.    routine returns a stream to which data should be fed. See also HTStreamStack which
  91.    scans the list of registered converters and calls one. See the initialisation module
  92.    for a list of conversion routines.
  93.    
  94.  */
  95. typedef struct _HTPresentation HTPresentation;
  96.  
  97. typedef HTStream * HTConverter PARAMS((
  98.         HTPresentation *        pres,
  99.         HTParentAnchor *        anchor,
  100.         HTStream *              sink));
  101.         
  102. struct _HTPresentation {
  103.         HTAtom* rep;            /* representation name atmoized */
  104.         HTAtom* rep_out;        /* resulting representation */
  105.         HTConverter *converter; /* The routine to gen the stream stack */
  106.         char *  command;        /* MIME-format string */
  107.         float   quality;        /* Between 0 (bad) and 1 (good) */
  108.         float   secs;
  109.         float   secs_per_byte;
  110. };
  111.  
  112. /*
  113.  
  114.    The list of presentations is kept by this module.  It is also scanned by modules which
  115.    want to know the set of formats supported. for example.
  116.    
  117.  */
  118. extern HTList * HTPresentations;
  119.  
  120. /*
  121.  
  122. HTSetPresentation: Register a system command to present a format
  123.  
  124. On entry,
  125.  
  126.   rep                     is the MIME - style format name
  127.                          
  128.   command                 is the MAILCAP - style command template
  129.                          
  130.   quality                 A degradation faction 0..1
  131.                          
  132.   maxbytes                A limit on the length acceptable as input (0 infinite)
  133.                          
  134.   maxsecs                 A limit on the time user will wait (0 for infinity)
  135.                          
  136.  */
  137. extern void HTSetPresentation PARAMS((
  138.         CONST char * representation,
  139.         CONST char * command,
  140.         float   quality,
  141.         float   secs,
  142.         float   secs_per_byte
  143. ));
  144.  
  145.  
  146. /*
  147.  
  148. HTSetConversion:   Register a converstion routine
  149.  
  150. On entry,
  151.  
  152.   rep_in                  is the content-type input
  153.                          
  154.   rep_out                 is the resulting content-type
  155.                          
  156.   converter               is the routine to make the stream to do it
  157.                          
  158.  */
  159.  
  160. extern void HTSetConversion PARAMS((
  161.         CONST char *    rep_in,
  162.         CONST char *    rep_out,
  163.         HTConverter *   converter,
  164.         float           quality,
  165.         float           secs,
  166.         float           secs_per_byte
  167. ));
  168.  
  169.  
  170. /*
  171.  
  172. HTStreamStack:   Create a stack of streams
  173.  
  174.    This is the routine which actually sets up the conversion. It currently checks only for
  175.    direct conversions, but indirect conversions are forseen. It takes a stream into which
  176.    the output should be sent in the final format, builds the conversion stack, and returns
  177.    a stream into which the data in the input format should be fed.  The anchor is passed
  178.    because hypertxet objects load information into the anchor object which represents
  179.    them.
  180.    
  181.  */
  182. extern HTStream * HTStreamStack PARAMS((
  183.         HTFormat                format_in,
  184.         HTFormat                format_out,
  185.         HTStream*               stream_out,
  186.         HTParentAnchor*         anchor));
  187.  
  188. /*
  189.  
  190. HTStackValue: Find the cost of a filter stack
  191.  
  192.    Must return the cost of the same stack which HTStreamStack would set up.
  193.    
  194. On entry,
  195.  
  196.   format_in               The fomat of the data to be converted
  197.                          
  198.   format_out              The format required
  199.                          
  200.   initial_value           The intrinsic "value" of the data before conversion on a scale
  201.                          from 0 to 1
  202.                          
  203.   length                  The number of bytes expected in the input format
  204.                          
  205.  */
  206. extern float HTStackValue PARAMS((
  207.         HTFormat                format_in,
  208.         HTFormat                rep_out,
  209.         float                   initial_value,
  210.         long int                length));
  211.  
  212. #define NO_VALUE_FOUND  -1e20           /* returned if none found */
  213.  
  214. /*
  215.  
  216. HTCopy:  Copy a socket to a stream
  217.  
  218.    This is used by the protocol engines to send data down a stream, typiclly one which has
  219.    been generated by HTStreamStack.
  220.    
  221.  */
  222. extern void HTCopy PARAMS((
  223.         int                     file_number,
  224.         HTStream*               sink));
  225.  
  226.         
  227. /*
  228.  
  229.    HTCopyNoCRThis one strips CR characters. It is slower than HTCopy .
  230.    
  231.  */
  232.  
  233. extern void HTCopyNoCR PARAMS((
  234.         int                     file_number,
  235.         HTStream*               sink));
  236.  
  237.  
  238. /*
  239.  
  240. Clear input buffer and set file number
  241.  
  242.    This routine and the one below provide simple character input from sockets. (They are
  243.    left over from the older architecure and may not be used very much.)  The existence of
  244.    a common routine and buffer saves memory space in small implementations.
  245.    
  246.  */
  247. extern void HTInitInput PARAMS((int file_number));
  248.  
  249. /*
  250.  
  251. Get next character from buffer
  252.  
  253.  */
  254. extern char HTGetChararcter NOPARAMS;
  255.  
  256.  
  257. /*
  258.  
  259. HTParseSocket: Parse a socket given its format
  260.  
  261.    This routine is called by protocol modules to load an object.  uses HTStreamStack and
  262.    the copy routines above.  Returns HT_LOADED if succesful, <0 if not.
  263.    
  264.  */
  265. extern int HTParseSocket PARAMS((
  266.         HTFormat        format_in,
  267.         HTFormat        format_out,
  268.         HTParentAnchor  *anchor,
  269.         int             file_number,
  270.         HTStream*       sink));
  271.  
  272. /*
  273.  
  274. Epilogue
  275.  
  276.  */
  277. extern BOOL HTOutputSource;     /* Flag: shortcut parser */
  278. #endif
  279.  
  280. /*
  281.  
  282.    end  */
  283.